package cn.tedu.text;

import java.sql.*;

public class Dao {

    //创建于数据库的连接
    public static Connection conn() {
        Connection conn=null;
        try {
            //1.加载驱动
            Class.forName("com.mysql.jdbc.Driver");
            //2.创建数据库的连接
            conn= DriverManager.getConnection(
                    "jdbc:mysql://localhost:3307/cgb2104?characterEncoding=utf8","root","root");


        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    return conn;
    }


  //关闭资源的
        public static void  close(ResultSet re, PreparedStatement st, Connection con) {

            if (re != null) {
                try {
                    re.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                } finally {
                    re = null;
                }
            }
            if (st != null) {
                try {
                    st.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                } finally {
                    st = null;
                }
            }
            if (con != null) {
                try {
                    con.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                } finally {
                    con = null;
                }
            }


        }


}
